package com.li.hello.service.impl;

import com.li.hello.domain.PersionDao;
import com.li.hello.entity.Persion;
import com.li.hello.service.PersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * spring、redis缓存注解
 */
@Service
public class PersionServiceImpl implements PersionService {
    @Autowired
    private PersionDao persionDao;

    /**
     * 对于一个支持缓存的方法，Spring会在其被调用后将其返回值缓存起来，
     * 以保证下次利用同样的参数来执行该方法时可以直接从缓存中获取结果，而不需要再次执行该方法
     *
     * @param persion
     * @return
     */
    @Override
    @CachePut(value = "persion", key = "#persion.id")
    public Persion setPersion(Persion persion) {
        persionDao.setPersion(persion);
        return persion;
    }

    @Override
    @Cacheable(value = "persion", key = "#persion.id")
    public Persion getPersion(Persion persion) {
        return persionDao.getPersion(persion);
    }
}
